import {Base} from '../../utils/base.js';
class Order extends Base{
  constructor()
  {
    super();
  }

  //根据商品ID以及商品规格ID获取商品的信息
  getProductDetail(id,sku_id,callback)
  {
    var that = this;
    var params = {
      url:'goods/order_goods_detail?id='+id + '&sku_id='+sku_id,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //下单
  doOrder(data,callback)
  {
    var that = this;
    var params = {
      url:'order/do_order',
      type:'POST',
      data:data,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }
  //发起预授权
  orderFree(id,callback)
  {
    var that = this;
    var params = {
      url:'order/freeze?id='+id,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //人脸认证结果查询接口
  faceNotify(params,callback)
  {
    var that = this;
    var params = {
      url:'ali/face',
      type:'POST',
      data:params,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //预授权成功后接口
  freeBack(params,callback)
  {
    var that = this;
    var params = {
      url:'fnotify',
      type:'POST',
      data:params,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //获取我的默认地址
  getMyDefaultAddress(uid,callback)
  {
    var that = this;
    var params = {
      url:'address/mydefault?uid='+uid,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //根据订单ID获取订单以及订单商品的ID
  getOrderAndProductDetail(id,callback)
  {
    var that = this;
    var params = {
      url:'order/order_detail?id='+id,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //获取订单的预支付信息
  getPreOrder(orderId,orderNo,callback)
  {
    var that = this;
    var params = {
      url:'Pay/preOrder?orderId='+orderId+'&orderNo='+orderNo,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //信用借还订单创建
  getZhimaOrder(params,callback)
  {
    var that = this;
    var params = {
      url:'Order/zhima',
      type:'POST',
      data:params,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //订单创建成功后的回调
  payNotify(orderid,callback)
  {
    var that = this;
    var params = {
      url:'paynotify?orderid='+orderid,
      sCallback:function(data)
      {
        callback && callback(data);

      }

    };
    this.request(params);
  }

  //获取订单和分期订单的相关信息通过订单ID
  getOrderRentAndOrderProduct(id,callback)
  {
    var that = this;
    var params = {
      url:'order_rent_product?id='+id,
      sCallback:function(data)
      {
        callback && callback(data);

      }

    };
    this.request(params);
  }

  //将地址写入订单地址表中
  addOrderAddress(addressid,orderid,callback)
  {
      var that = this;
      var params = {
      url:'order/address?addressid='+addressid+'&orderid='+orderid,
      sCallback:function(data)
      {
        callback && callback(data);

      }

    };
    this.request(params);
  }

  //判断是否已经授权过
  isAuth(orderid,callback)
  {
     var that = this;
      var params = {
      url:'order/isauth?orderid='+orderid,
      sCallback:function(data)
      {
        callback && callback(data);

      }

    };
    this.request(params);
  }

  //判断是否有租约在身
  isInRent(uid,callback)
  {
    var that = this;
      var params = {
      url:'isinrent?uid='+uid,
      sCallback:function(data)
      {
        callback && callback(data);

      }

    };
    this.request(params);
  }

  //还款
  payBack(params,callback)
  {
    var that = this;
    var params = {
      url:'rent/doorder',
      type:'POST',
      data:params,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //还款支付
  payBackReturn(orderId,orderNo,callback)
  {
    var that =this;
    var params = {
      url:"rent/pay?orderId="+orderId+'&orderNo='+orderNo,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

  //还款支付回调
  payBackNotify(orderid,callback)
  {
     var that =this;
    var params = {
      url:"rent/notify?orderid="+orderid,
      sCallback:function(data)
      {
        callback && callback(data);
      }
    };
    this.request(params);
  }

}
export {Order};